<?php
class Administration_Form_Players extends Jnd_Form
{
	protected $_teams = array();
	
    public function __construct( $teams = array(), $decorateur = "Formulairejnd", $options = null )
    {
    	$this->_teams = $teams;
        parent::__construct($decorateur, $options);
        $this->setElementDecorators(array(
            "$decorateur"
        ), array(
            'pictures'
        ), false);
    }

    public function init()
    {
        
        //
        // Field id
        $field = new Zend_Form_Element_Text("id");
        $field->setLabel('Id');
        $field->setAttribs(array(
            'readonly' => 'readonly', 
            'class' => 'readonly'
        ));
        $field->setFilters(array(
            'Digits'
        ));
        $fields[] = $field;
        
        //
        //	Field team
        $field = new Zend_Form_Element_Select("idTeams");
        $field->setLabel(__('Team'));
        $field->setMultiOptions($this->_teams);
        $field->setRequired(true);
        $fields[] = $field;
        
        //
        //  Field Lastname
        $field = new Zend_Form_Element_Text("lastname");
        $field->setLabel(_('Lastname'));
        $field->setRequired(true);
        $fields[] = $field;
        
        //
        //  Field Firstname
        $field = new Zend_Form_Element_Text("firstname");
        $field->setLabel(_('Firstname'));
        $field->setRequired(true);
        $fields[] = $field;
        
        //
        //  Field Nickname
        $field = new Zend_Form_Element_Text("nickname");
        $field->setLabel(_('Nickname'));
        $field->setRequired(true);
        $fields[] = $field;
        
        //
        //  Field Number
        $field = new Zend_Form_Element_Text("number");
        $field->setLabel(_('Number'));
        $fields[] = $field;
        
        //
        //  Field height
        $field = new Zend_Form_Element_Text("height");
        $field->setLabel(_('Height'));
        $fields[] = $field;
        
        //
        //  Field weight
        $field = new Zend_Form_Element_Text("weight");
        $field->setLabel(_('Weight'));
        $fields[] = $field;
        
        //	
        //	Field Shoots
        $field = new Zend_Form_Element_Radio("shoots");
        $field->setLabel(__('Shoots'));
        $field->setMultiOptions(array(
            "R" => __('Right hand'), 
            "L" => __('Left hand')
        ));
        $fields[] = $field;
        
        //
        //	Field Born
        $field = new Jnd_Form_Element_DatePicker("born");
        $field->setLabel(__('Birthdate'));
        $fields[] =  $field;
        
        if ( $this->_decorator != "Voir" ) {
        	//
            //  CField Picture
            $element = new Zend_Form_Element_File('pictures');
            $element->setLabel(__('Choose a picture'))->setDestination(dirname(APPLICATION_PATH) . "/public/images/players/pictures");
            // ensure only 1 file
            $element->addValidator('Count', false, 1);
            // limit to 100K
            $element->addValidator('Size', false, 102400);
            // only JPEG, PNG, and GIFs
            $element->addValidator('Extension', false, 'jpg,jpeg,png,gif');
            //        $element->setDecorators(array("Formulaireddb"));
        } else {
        	$element = new Zend_Form_Element_Image("pictures");
        }
        $fields[]= $element;
        
        $this->addElements($fields);
        
        //
        //  Champ creationUser
        $this->addElement("text", "creationUser", array(
            'label' => __('Created by'), 
            'readonly' => 'readonly', 
            'class' => 'readonly', 
            'filters' => array()
        ));
        
        //
        //  Champ creationDate
        $this->addElement("text", "creationDate", array(
            'label' => __('Created'), 
            'readonly' => 'readonly', 
            'class' => 'readonly', 
            'value' => date(Jnd_Global_Constantes::FORMAT_DATE_HEURE_WEB_COURT)
        ));
        
        $this->setName("players");
    }

}